package com.sxm.yiwei.pinche;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.sxm.yiwei.MainActivity;
import com.sxm.yiwei.R;
import com.sxm.yiwei.adapters.pinche.PincheOrderFragmentAdapter;
import com.sxm.yiwei.base.BaseActivity;
import com.sxm.yiwei.base.BaseFragment;
import com.sxm.yiwei.constant.Constant;

import java.util.ArrayList;

public class PincheOrderActivity extends BaseActivity {


    private RelativeLayout rl_back;
    private TextView tv_title;
    private RelativeLayout rl_back_home;
    private TabLayout mTabLayout;
    private ViewPager mViewPager;
    private int identity;
    private int order_type;
    private ArrayList<BaseFragment> mFragment=new ArrayList<>();
    private PincheOrderFragmentAdapter mAdapter;


    @Override
    public void setContentView() {
        identity = getIntent().getIntExtra("identity",-1);
        order_type = getIntent().getIntExtra("order_type",-1);
        setContentView(R.layout.activity_pinche_order);
    }

    @Override
    public void initView() {
        rl_back = (RelativeLayout)findViewById(R.id.rl_back);
        tv_title = (TextView)findViewById(R.id.tv_title);
        rl_back_home = (RelativeLayout)findViewById(R.id.rl_back_home);
        mTabLayout = (TabLayout)findViewById(R.id.tablayout);
        mViewPager = (ViewPager)findViewById(R.id.viewpager);

    }

    @Override
    public void initListener() {
        rl_back.setOnClickListener(this);
        rl_back_home.setOnClickListener(this);
    }

    @Override
    public void initData() {
        if (identity == Constant.PASSENGER) {
            switch (order_type) {
                case Constant.WAIT_PAY:
                    tv_title.setText("我是乘客——待付款");
                    break;
                case Constant.WAIT_TAKE:
                    tv_title.setText("我是乘客——待接单");
                    break;
                case Constant.WAIT_SURVICE:
                    tv_title.setText("我是乘客——待服务");
                    break;
                case Constant.IN_SURVICE:
                    tv_title.setText("我是乘客——服务中");
                    break;
                case Constant.WAIT_FINISH:
                    tv_title.setText("我是乘客——待完结");
                    break;
                case Constant.FINISHED:
                    tv_title.setText("我是乘客——已完结");
                    break;
                case Constant.LOSS:
                    tv_title.setText("我是乘客——爽约单");
                    break;
                case Constant.EXCEPTION:
                    tv_title.setText("我是乘客——订单异常");
                    break;
            }
        } else if (identity == Constant.HOST) {
            switch (order_type) {
                case Constant.WAIT_PAY:
                    tv_title.setText("我是车主——待付款");
                    break;
                case Constant.WAIT_TAKE:
                    tv_title.setText("我是车主——待接单");
                    break;
                case Constant.WAIT_SURVICE:
                    tv_title.setText("我是车主——待服务");
                    break;
                case Constant.IN_SURVICE:
                    tv_title.setText("我是车主——服务中");
                    break;
                case Constant.WAIT_FINISH:
                    tv_title.setText("我是车主——待完结");
                    break;
                case Constant.FINISHED:
                    tv_title.setText("我是车主——已完结");
                    break;
                case Constant.LOSS:
                    tv_title.setText("我是车主——爽约单");
                    break;
                case Constant.EXCEPTION:
                    tv_title.setText("我是车主——订单异常");
                    break;

            }
        }
        initTabLayout();
    }
    private void initTabLayout(){
        mFragment.clear();
        for (int i = 0; i < 4; i++) {
            PincheOrderFragment fragment = new PincheOrderFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("identity",identity);
            bundle.putInt("order_type",order_type);
            bundle.putInt("go_type",i);
            fragment.setArguments(bundle);
            mFragment.add(fragment);
        }

        mAdapter = new PincheOrderFragmentAdapter(getSupportFragmentManager(),mFragment,this);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setOffscreenPageLimit(4);

        mTabLayout.setupWithViewPager(mViewPager);
        mViewPager.setCurrentItem(0);

        mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                mViewPager.setCurrentItem(tab.getPosition());
            }
            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }
            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.rl_back_home:
                startActivity(new Intent(this, MainActivity.class));
                finish();
                break;
        }
    }
}
